package com.tiancheng.trade.payment.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tiancheng.trade.commom.core.data.PageInfo;

/**
 * 基础mapper
 *
 * @author kellen
 * @date 2019-10-30
 */
public interface TYBaseMapper<T> extends BaseMapper<T> {

    /**
     * 分页查询
     * @param var2
     * @param page
     * @param limit
     * @return
     */
    default PageInfo<T> find(Wrapper<T> var2, int page, int limit) {
        IPage<T> pageResult = this.selectPage(new Page<>(page, limit), var2);
        PageInfo.Pagination pagination = new PageInfo.Pagination(pageResult.getCurrent(), (int) pageResult.getSize(),
                pageResult.getTotal());
        return new PageInfo<>(pageResult.getRecords(), pagination);
    }

    /**
     * 转换成自定义的分页对象
     * @param pageResult
     * @return
     */
    default PageInfo convertPage(IPage pageResult) {
        PageInfo.Pagination pagination = new PageInfo.Pagination(pageResult.getCurrent(), (int) pageResult.getSize(),
                pageResult.getTotal());
        return new PageInfo<>(pageResult.getRecords(), pagination);
    }
}
